import { REACT_TEXT } from "./constants";
export function wrapToVdom(element) {
  return typeof element === "string" || typeof element === "number"
    ? { type: REACT_TEXT, props: { content: element } }
    : element;
}


export function shallowEqual(obj1,obj2){
  if(obj1 === obj2){ //如果两个对象地址一样，就认为相等的
    return true
  }
  // 只要任何一个不是对象或者是null，那就不想等
  if(typeof obj1 !== 'object'|| obj1 === null|| typeof obj2 != "object" || obj2 === null){
    return false
  }
  let keys1 = Object.keys(obj1)
  let keys2 = Object.keys(obj2)
  // 如果属性的数量不想等，就是不想等
  if(keys1.length !== keys2.length){
    return false
  }
  // console.log(obj1,obj2)
  // console.log(keys1,keys2)

  //遍历obj，只比较第一层
    for (let key of keys1) {
        if (!obj2.hasOwnProperty(key)  || obj1[key] !== obj2[key]) {
          // console.log(obj1[key] ,obj2[key])
          return false;
        }
      }
  return true;
}

